package com.dwxt.sport.admin.controller;

import com.dwxt.common.base.BaseResult;
import com.dwxt.common.base.Page;
import com.dwxt.sport.admin.service.DeviceServiceAdmin;
import com.dwxt.sport.business.entity.DictValue;
import com.dwxt.sport.entity.WifeDevice;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RequestMapping("/admin")
@RestController
@Api(tags = {"设备相关接口"})
public class DeviceControllerAdmin {

    @Autowired
    private DeviceServiceAdmin deviceServiceAdmin;


    @ApiOperation(value = "查询设备列表", notes = "查询设备列表", response = WifeDevice.class)
    @PostMapping("/selectDevicePage")
    public BaseResult selectDevicePage(Page page, WifeDevice wifeDevice) {
        return deviceServiceAdmin.selectDevicePage(page, wifeDevice);
    }

    /**
     * 创建设备
     *
     * @param wifeDevice
     * @return
     */
    @ApiOperation(value = "新增设备", notes = "新增设备", response = BaseResult.class)
    @PostMapping("/createDevice")
    public BaseResult createDevice(WifeDevice wifeDevice) {
        return deviceServiceAdmin.createDevice(wifeDevice);
    }

    /**
     * 修改设备
     *
     * @param wifeDevice
     * @return
     */
    @ApiOperation(value = "修改设备", notes = "修改设备", response = BaseResult.class)
    @PostMapping("/updateDevice")
    public BaseResult updateDevice(WifeDevice wifeDevice) {
        return deviceServiceAdmin.updateDevice(wifeDevice);
    }


    /**
     * 删除设备
     *
     * @param id
     * @return
     */
    @ApiOperation(value = "删除设备", notes = "删除设备", response = BaseResult.class)
    @PostMapping("/deleteDevice")
    public BaseResult deleteDevice(@ApiParam(value = "id", required = true) String id) {
        deviceServiceAdmin.deleteDevice(id);
        return BaseResult.ok();
    }

    /**
     * 启用或停用设备
     *
     * @param id
     * @return
     */
    @ApiOperation(value = "启用或停用设备", notes = "启用或停用设备", response = BaseResult.class)
    @PostMapping("/upOrDown")
    public BaseResult upOrDown(@ApiParam(value = "id", required = true) String id) {
        deviceServiceAdmin.upOrDown(id);
        return BaseResult.ok();
    }

    @PostMapping("/selectDeviceGroup")
    @ApiOperation(value = "分组查询设备", notes = "分组查询设备", response = BaseResult.class)
    public BaseResult selectDeviceGroup() {
        return deviceServiceAdmin.selectDeviceGroup();
    }

    @PostMapping("/selectDeviceType")
    @ApiOperation(value = "查询设备类型", notes = "查询设备类型", response = DictValue.class)
    public BaseResult selectDeviceType(){
            return deviceServiceAdmin.selectDeviceType();
    }

    @PostMapping("/selectDeviceModelByType")
    @ApiOperation(value = "查询设备型号", notes = "查询设备型号", response = DictValue.class)
    public BaseResult selectDeviceModelByType(Integer type){
        return deviceServiceAdmin.selectDeviceModelByType(type);
    }

}
